home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
300_01
/
contour.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-28
|
24KB
|
457 lines
/* HEADER: CUG300;
TITLE: Contour ploting demonstration;
DATE: 4/20/1989;
DESCRIPTION: "Plot contours using mat.lib functions";
VERSION: 2.04;
FILENAME: CONTOUR.C;
SEE-ALSO: MAT_V2D.H;
*/
/*===================================================================*/
/* ROUTINES TO GENERATE CADD CONTOUR LINES FROM INPUT GRID VALUES */
/*===================================================================*/
/* 0,1 1,1 */
/* m4.-----------.m3 ^ 0,jub */
/* | . . | | */
/* | . . | | */
/* | .m0 | | */
/* | . . | | */
/* | . . | | */
/* m1|___________|m2 0,0 --------------> iub,0 */
/* 0,0 1,0 */
/* */
/* grid square layout coordinate system layout */
/* ------------------- ------------------------ */
/*===================================================================*/
#include <stdio.h>
#include "mat_v2d.h"
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#define FALSE 0
#define TRUE 1
#define NO_ROWS 24
#define NO_COLS 72
#define xchk(x) if(x<0)puts("x<0");if(x>NO_COLS)puts("x>NO_COLS")
#define ychk(y) if(y<0)puts("y<0");if(y>NO_COLS)puts("y>NO_COLS")
void box (float x1,float y1,float x2,float y2 );
void dda (float x1,float y1,float x2,float y2,char symbol);
void display (void);
void erase (void);
void GridSelect (int iub, int jub, int nc, struct fmat *x,
struct fmat *y,struct fmat *d, struct fmat *z);
void ContourSelect (int i,int j, int nc,struct fmat *x,
struct fmat *y,struct fmat *d,struct fmat *z,
int iub, int jub);
void drawit (float x1, float x2, float y1, float y2,
struct fmat *x, struct fmat *y,int iub,int jub );
void set_graphics (void);
void file_output (void);
char frame[NO_COLS][NO_ROWS];
/*============================================================================*/
main()
/*============================================================================*/
{
int i,i1,j,j1,k,iub,jub,nc,prmerr,num_rows,num_cols,token_size;
struct fmat *x,*y,*d,*z;
struct tmat *input_data;
char filename[20];
/* Input arrays and indexes */
printf("Enter contour data filename => ");
scanf("%s",filename);
mtcnt(filename,&num_rows,&num_cols,&token_size); /* Get input file size */
tdim(input_data,num_rows,num_cols,token_size); /* Dimension input */
mtget(filename,input_data); /* array */
iub = no_toks(input_data,0); /* Get indices from */
jub = no_toks(input_data,1); /* the number of tokens*/
nc = no_toks(input_data,2); /* stored in the */
/* appropriate input */
fdim(d,iub,jub+1); /* data line header */
fdim(x,iub,DCLVCT);
fdim(y,jub,DCLVCT); /* Dimension needed */
fdim(z,nc,DCLVCT); /* arrays */
for(i=0; i<iub; i++) { /* Store x grid loca- */
fck(x,i,VCT); /* tion. */
f(x,i,VCT) = tf(input_data,0,i,iub);
}
for(j=0; j<jub; j++) { /* Store y grid loca- */
fck(y,j,VCT); /* tions */
f(y,j,VCT) = tf(input_data,1,j,jub);
}
for(i=0; i<nc; i++) { /* Store contour */
fck(z,i,VCT); /* levels to be */
f(z,i,VCT) = tf(input_data,2,i,nc); /* plotted */
}
for (j=3,k=jub-1; j<num_rows; j++,k--) {
for (i=0; i<iub; i++) { /* Store f(x,y) for */
fck(d,i,k); /* each grid line */
f(d,i,k) = tf(input_data,j,i,iub); /* intersection */
}
}
iub--;jub--;
/* Check input parameters for validity */
prmerr = FALSE; /* Test for no grid */
if (iub<=0 || jub<=0) /* intersections. */
prmerr = TRUE; /* */
if (nc <=0) /* No contours */
prmerr = TRUE; /* requested */
for (k = 1; k <= (nc-1); k++) /* */
{ /* */
if (f(z,k,VCT) <= f(z,k-1,VCT) ) /* Duplicate contours */
prmerr = TRUE; /* */
} /* */
if (prmerr) /* */
{ /* */
printf ("Error in input parameters"); /* Message if any */
return; /* errors found */
} /* */
set_graphics(); /* Initialize graphic */
/* frame buffer */
GridSelect (iub, jub, nc, x, y, d, z ); /* Plot contours */
/* */
display(); /* Display all */
/* contours plotted */
file_output(); /* */
/* Place contour in */
/* an ASCII file */
} /* */
/*============================================================================*/
void GridSelect ( int iub, int jub, int nc, struct fmat *x,
struct fmat *y,struct fmat *d, struct fmat *z )
/*============================================================================*/
{
int i, j;
/* Scan the input array top down & left to right */
for (j = (jub-1); j >= 0; j--)
{
for (i = 0; i <= (iub-1); i++)
{
ContourSelect (i,j,nc,x,y,d,z,iub,jub); /* Select contour to */
} /* plot */
}
}
/*============================================================================*/
void ContourSelect ( int i,int j, int nc,struct fmat *x,
struct fmat *y, struct fmat *d,
struct fmat *z, int iub, int jub )
/*============================================================================*/
{
/* Declare & initialize variables */
float h [5], xh [5], yh[5];
int ish[5];
int caseval,k,i1,j1,m1, m2, m3;
int m;
static int im[4] = { 0,